<?php 
/**
 * 奖券任务
 */
class CoinTaskRewardList extends APIBase {

	public $tag = "CoinTaskRewardList";

	public function before() {
		$this->initCacheRedis();
		return true;
	}

	public function logic() {
		
		$coin_task = $this->data_redis->hMget("hu:{$this->uid}",array("coin_task_complete_record", "isget_coin_task_reward_record"));	
		$coin_task_complete_record = $coin_task['coin_task_complete_record'];
		$isget_coin_task_reward_record = (int)$coin_task['isget_coin_task_reward_record'];		
		//获取任务的完成进度		
		//$coin_task_complete_record = "1|2|50|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0";
		$task_pieces = explode("|", $coin_task_complete_record);
		var_dump($task_pieces);
		
		$taskids = $this->cache_redis->lRange("lcointask:ids", 0, -1);
		$tasks = array();
		foreach ($taskids as $tid) {
			$task = $this->cache_redis->hMGet("hcointask:{$tid}", array("id", "name", "task_reward_coin", "task_value"));
			$tid = (int)$tid;
			$task['id'] = $tid;
			$task['name'] = (string) $task['name'];
			$task['task_reward_coin'] = (int) $task['task_reward_coin'];
			$task['task_value'] = (int) $task['task_value'];
						
			//如果奖券任务完成度 >= 奖励任务的规定完成度，则任务完成
			if ( (int) $task_pieces[$tid -1] >= $task["task_value"] )
			{
				
				$task['task_complete_value'] = $task['task_value'];
				
				//任务完成，未领取
				if ( ($isget_coin_task_reward_record & (1 << $tid-1)) == 0)
				{
					$task['flag'] = 1;
				}
				//任务完成，已经领取
				else
				{
					$task['flag'] = 2;
				}
			}
			//否则任务没有完成,完成值等于 $task_pieces[$tid -1 ], $task['flag'] = 0;
			else
			{
				$task['task_complete_value'] = (int)$task_pieces[$tid - 1];
				$task['flag'] = 0;
			}		
				
			$tasks[] = $task;
			
		}
						
		$this->returnData(array('cointasks' => $tasks));
	}

	public function after() {
		$this->deinitCacheRedis();
		$this->deinitDataRedis();
	}
}

?>